package kotan;

class Options {

    boolean production = false;
    String[] kinds = new String[] { "_KotanEntity" };
    String email = "test@example.com";
    AppEngineEnv env = new AppEngineEnv();

    Options(String[] args) throws InitalizeException {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("-production=")) {
                this.production = Boolean.parseBoolean(arg.substring("-production=".length()));
            } else if (arg.startsWith("-sdkHome=")) {
                this.env.sdkHome = arg.substring("-sdkHome=".length());
            } else if (arg.startsWith("-host=")) {
                this.env.host = arg.substring("-host=".length());
            } else if (arg.startsWith("-port=")) {
                this.env.port = Integer.parseInt(arg.substring("-port=".length()));
            } else if (arg.startsWith("-nameSpace=")) {
                this.env.nameSpace = arg.substring("-nameSpace=".length());
            } else if (arg.startsWith("-kinds=")) {
                this.kinds = arg.substring("-kinds=".length()).split(",");
            } else if (arg.startsWith("-email=")) {
                this.email = arg.substring("-email=".length());
            }
        }
        if (!this.production && (env.sdkHome == null || env.sdkHome.length() == 0)) {
            throw new InitalizeException("Require appengine sdk home. -sdkHome=/path/to/appengine-sdk");
        }
    }
}
